//
//  ViewController.m
//  03-UIResponder
//
//  Created by Snow on 16/7/18.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    /* 1.重写touchesBegan:withEvent:方法，方法实现：NSLog输出指定方法名（__Function__）
     2.重写touchesMove:withEvent:方法，方法实现：NSLog输出指定方法名（__Function_）
     3.重写touchesEnd:withEvent:方法，方法实现：NSLog输出指定方法名（__Function__）。并给当前视图的背景颜色设置为随机色。
     */
    TouchView *touchView = [[TouchView alloc] initWithFrame:CGRectMake(10, 10, 355, 200)];
    touchView.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:touchView];
    //1.响应者链
    //检测顺序:硬件 -> APPDelegate -> UIAplication -> UIWindow -> UIViewController -> UIView -> TouchView
    //响应顺序
    //反过来 :TouchView -> UIView -> UIViewController -> UIWindow -> UIAplication -> APPDelegate -> null
    //如果所有的响应者 都无法响应 该事件 则这个事件会被舍弃
    // 两种检测响应者的方法
    //1.category 实现 touchBegin的方法
    //2.nextResponder
    
    //例:
    //1.响应者不要出边界 , 出边界的响应者无法响应
    // 判断当前的点 在谁的范围内
    BOOL isInside = [touchView pointInside:CGPointMake(10, 210) withEvent:nil];
    NSLog(@"%@", isInside ? @"Yes" : @"No");
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(20, 180, 200, 50);
    button.backgroundColor = [UIColor greenColor];
    [touchView addSubview:button];
    [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];//button超出了触摸范围
    //2.button的点击方法如何实现
    // button 点击效果 通过UIResponder对应的方法实现
    //3.pointInside重写 实现失去响应能力(return No)
    //imageView的用户交互是默认关闭的userinteractionenabled
}
- (void)handleButton:(UIButton *)button
{
    NSLog(@"button");
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
//    NSLog(@"%@---%s", [self class], __FUNCTION__);

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
